package net.zjitc.hashset.user;

import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/9 14:14
 */
public class test {
    static UserDao dao=new UserDaoHashset();
    public static void main(String[] args) {
        while (true) {
            System.out.println("----------------欢迎光临----------------");
            System.out.println("1-注册");
            System.out.println("2-退出");
            Scanner in = new Scanner(System.in);
            int a = in.nextInt();
            switch (a) {
                case 1:
                    zhuce();
                    break;
                case 2:
                    System.out.println("退出成功！");
                    System.exit(0);
                default:
                    System.out.println("输入有误！");
                    break;
            }
        }


    }
    private static void zhuce(){
        System.out.println("注册信息：");
        System.out.println("请输入用户名：");
        Scanner in=new Scanner(System.in);
        String name=in.nextLine();
        System.out.println("请输入密码：");
        String password=in.nextLine();
        System.out.println("请输入确认密码：");
        String confirmPassword=in.nextLine();
        while (!confirmPassword.equals(password)){
            System.out.println("确认密码与密码不一致，请重新输入确认密码：");
            confirmPassword=in.nextLine();
        }
        System.out.println("请输入手机号：");
        String phone=in.nextLine();
        while (!(phone.startsWith("13")||phone.startsWith("15")||
                phone.startsWith("17")|| phone.startsWith("18")||phone.length()!=11)){
            System.out.println("手机号必须是11位，且必须以13、15、17、18开头" );
            phone=in.nextLine();
        }
        System.out.println("请输入电子邮箱：");
        String email=in.nextLine();
        while (!email.contains("@")){
            System.out.println("邮箱得包含 @. 请重新输入");
            email=in.nextLine();

        }
        /* 把用户信息封装到用户对象 */
        User user=new User(name,password,phone,email);
        /* 调用工具类方法完成注册操作 */
        dao.register(user);

    }
}
